package com.example.flower_shop.vo.role;

import com.example.flower_shop.entity.RoleEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Schema(description = "角色分页返回对象")
public class RolePageRespVO {
    /**
     * ID
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Schema(description = "角色唯一标识符")
    private Long id;

    /**
     * 名称
     */
    @Schema(description = "角色名称", example = "管理员")
    private String name;

    /**
     * 角色标签
     */
    @Schema(description = "角色标签", example = "ADMIN")
    private String label;

    /**
     * 备注
     */
    @Schema(description = "备注信息", example = "此角色具有所有权限")
    private String remark;

    /**
     * 数据权限是否关联上下级
     */
    @Schema(description = "数据权限是否关联上下级", example = "true")
    private Boolean relevance;

    /**
     * 状态
     */
    @Schema(description = "角色状态", example = "true")
    private Boolean status;

    /**
     * 创建时间
     */
    @Schema(description = "角色创建时间")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Schema(description = "角色更新时间")
    private LocalDateTime updateTime;

    public static class Converter {
        public static List<RolePageRespVO> convert(List<RoleEntity> roles) {
            return roles.stream().map(role -> {
                RolePageRespVO respVO = new RolePageRespVO();
                BeanUtils.copyProperties(role, respVO);
                return respVO;
            }).collect(Collectors.toList());
        }
    }
}
